/*
 * =====================================================================================
 *
 *       Filename:  Card.cpp
 *
 *    Description:  Card implementation.
 *
 *        Version:  1.0
 *        Created:  10/25/11 11:41:59
 *       Revision:  none
 *       Compiler:  g++
 *
 *         Author:  LittleQ Su (), 98703060@nccu.edu.tw
 *        Company:  National Chengchi University, The Department of Computer Science
 *
 * =====================================================================================
 */

#include "headers.h"

// Implementation of Card

// Constructor
Card::Card() {
    this -> _suit = SPADES;
    this -> _point = 1;
}

Card::Card(Suit suit, int point) {
    this -> _suit = suit;
    this -> _point = point;
}

// Public
Card::Suit Card::getSuit(){
    return this -> _suit;
}

int Card::getPoint() {
    return this -> _point;
}

string Card::toString() {
    return this -> _getSuitString() + "_" + this -> _getRankString();
}

void Card::setId(int id) {
    this -> _id = id;
}

// Operator overloading
Card::Card& Card::operator=( Card::Card& card) {
    this -> _suit = card.getSuit();
    this -> _point = card.getPoint();

    return *this;
}



// Private
string Card::_getSuitString () {
    switch (this -> _suit) {
        case HEARTS:
            return "Hearts";
        case SPADES:
            return "Spades";
        case DIAMONDS:
            return "Diamonds";
        case CLUBS:
            return "Clubs";
    }
}

string Card::_getRankString() {
    int rank = this -> _point;
    char rankChar[2];
    sprintf(rankChar, "%d", rank);

    string rankString(rankChar);

    return rankString;
}

